#
# Copyright 2009 Jeffrey Palm
#

require 'common'

# A composed common implements all of the abstract methods of Common
# by composing various objects and calling to their interfaces.  It's
# composed of a:
#
#   - Player
#   - Library
#   - KeyFinder
#
class ComposedCommon < Common

  attr_reader :player
  attr_reader :library
  attr_reader :key_finder

  def initialize(config,player,library,key_finder)
    super         config
    @player     = player
    @library    = library
    @key_finder = key_finder
  end

  # ----------------------------------------------------------------------
  # Library methods
  # ----------------------------------------------------------------------

  def find_track(info)
    @library.find_track info
  end

  # ----------------------------------------------------------------------
  # Player methods
  # ----------------------------------------------------------------------

  def read_info(user=nil)
    @player.read_info user
  end

  def play_track(track_id)
    @player.play_track track_id
  end

  def pause_player
    @player.pause
  end

  # ----------------------------------------------------------------------
  # KeyFinder methods
  # ----------------------------------------------------------------------

  def find_the_shared_key
    @key_finder.find_the_shared_key
  end
  
end
